package com.thread;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@SpringBootApplication
public class ThreadApplication {

    static final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5,5,10, TimeUnit.SECONDS,new LinkedBlockingDeque<>());


    public static void main(String[] args) {
//		SpringApplication.run(ThreadApplication.class, args);

//		Executors.newCachedThreadPool();
//		ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5,5,10, TimeUnit.SECONDS,new LinkedBlockingDeque<>());
//		threadPoolExecutor.execute();
        for (int i = 0; i < 10; i++) {
            test();
        }
        threadPoolExecutor.shutdown();
    }

    public static void test() {
//        ExecutorService exec = Executors.newFixedThreadPool(10);
//        exec.execute(() -> {
//            try {
//                System.out.println(Thread.currentThread().getName()+":current thread runs");
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//
//        });
//        exec.shutdown();
        threadPoolExecutor.execute(() -> {
            try {
                System.out.println(Thread.currentThread().getName()+":current thread runs");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        );
    }
}
